package com.mida.app.report.controller;


import com.mida.app.report.service.DocStructTemplateInfoService;
import com.mida.bms.report.entity.DocStructTemplateInfo;
import com.mida.bms.report.vo.DocStructTemplateInfoVo;
import com.mida.bms.report.vo.PageResultVo;
import com.mida.tool.common.cons.RespConst;
import com.mida.tool.common.exception.MassertException;
import com.mida.tool.common.result.ActionResult;
import com.mida.tool.common.result.ListResult;
import com.mida.tool.common.validator.InsertValidator;
import com.mida.tool.common.validator.UpdateValidator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author ：dj
 * @description：模版基本信息
 */
@RestController
@RequestMapping("/docStructTemplateInfo")
@CrossOrigin
@Slf4j
public class DocStructTemplateInfoController {

    @Autowired
    private DocStructTemplateInfoService docStructTemplateInfoService;

    /**
     * 添加模版基本信息
     * @param docStructTemplateInfoVo
     * @return
     */
    @PostMapping(value = "/addDocStructTemplateInfo",produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ActionResult addDocStructTemplateInfo(
            @Validated (InsertValidator.class)
            @RequestBody DocStructTemplateInfoVo docStructTemplateInfoVo) {
        try {
             return docStructTemplateInfoService.addDocStructTemplateInfo(docStructTemplateInfoVo);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            throw new MassertException(
                    RespConst.newMsgError("添加模版基本信息失败,请联系管理员"));
        }
    }

    /**
     * 修改模版数据
     *
     * @param docStructTemplateInfoVo 对象接收前端传入的json
     * @return
     */
    @PostMapping(value = "/updateDocStructTemplateInfo",produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ActionResult updateDocStructTemplateInfo(
            @Validated(UpdateValidator.class)
            @RequestBody DocStructTemplateInfoVo docStructTemplateInfoVo) {
        try {
            return docStructTemplateInfoService.updateDocStructTemplateInfo(docStructTemplateInfoVo);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            throw new MassertException(
                    RespConst.newMsgError("修改模版数据失败,请联系管理员"));
        }
    }

    /**
     * 删除模版数据
     *
     * @param stTemplateInfoSoid 对象接收前端传入的json
     * @return
     */
    @PostMapping(value = "/deleteDocStructTemplateInfo",produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ActionResult deleteDocStructTemplateInfo(Long stTemplateInfoSoid) {
        try {
            return docStructTemplateInfoService.deleteDocStructTemplateInfo(stTemplateInfoSoid);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            throw new MassertException(
                    RespConst.newMsgError("删除模版数据失败,请联系管理员"));
        }
    }

    /**
     * 查询模板分页列表处理
     *
     * @param docStructTemplateInfoVo 对象接收前端传入的json
     * @return
     */
    @PostMapping(value = "/getDocStructTemplateInfoPage",produces = {"application/json;charset=UTF-8"})
    public ListResult<PageResultVo<DocStructTemplateInfo>> getDocStructTemplateInfoPage(
            @RequestBody DocStructTemplateInfoVo docStructTemplateInfoVo) {
        try {
             return docStructTemplateInfoService.getDocStructTemplateInfoPage(docStructTemplateInfoVo);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            throw new MassertException(
                    RespConst.newMsgError("查询模板分页列表处理失败,请联系管理员"));
        }
    }

    /**
     * 根据模板soid查询模版数据
     *
     * @param stTemplateInfoSoid 对象接收前端传入的json
     * @return
     */
    @PostMapping(value = "/getDocStructTemplateInfo",produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ListResult getDocStructTemplateInfo(Long stTemplateInfoSoid) {
        try {
            return docStructTemplateInfoService.getDocStructTemplateInfo(stTemplateInfoSoid);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            throw new MassertException(
                    RespConst.newMsgError("根据模板soid查询模版数据失败,请联系管理员"));
        }
    }
}
